package org.severedelays.android;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.SortedMap;

public class TubeStatus extends Activity {
  private static final String TUBE_STATUS_API = "http://status.severedelays.org/uk-lon/current?format=json";
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    StatusDownloader sd = new StatusDownloader(TUBE_STATUS_API);
    sd.downloadStatus();
    ArrayList<TubeLine> tls = sd.getLines();
    for (TubeLine t : tls) {
      TextView v = (TextView) findViewById(getStatusViewIdByLineName(t.getName()));
      v.setText(t.getStatus());
    }
  }
  
  public  int getStatusViewIdByLineName(String name) {
    SortedMap<String, Integer> ids = AndroidLineResources.NAMES;
    return ids.get(name + "_status");
  }
}